package com.example.combwx.mvp.base.presenter;

import android.util.Log;

import com.example.combwx.mvp.base.model.BaseEntity;
import com.example.combwx.mvp.base.model.IModel;
import com.example.combwx.mvp.base.view.IView;

import io.reactivex.Observer;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

public abstract class BasePresenter<M extends IModel,V extends IView>
        implements IPresenter, Observer<BaseEntity> {

    protected M m;
    protected V v;
    protected CompositeDisposable compositeDisposable;

    public BasePresenter(M m,V v){
        this.m =m;
        this.v=v;
        compositeDisposable = new CompositeDisposable();
    }

    @Override
    public void onDestrory() {

        compositeDisposable.dispose();
        compositeDisposable.clear();

    }

    @Override
    public void onSubscribe(Disposable d) {
        Log.i("XRN", "onSubscribe: "+11);
        compositeDisposable.add(d);
        v.showDialog();
    }
    @Override
    public void onError(Throwable e) {
        v.showMsg(e.getMessage());
    }

    @Override
    public void onComplete() {
        v.hideDialog();
    }
}
